package com.tjshop.android.model;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by gytaiSSD on 2015/1/6.
 */
public class CouponDetail {
	private String name;// "name": "乐峪29元6小时欢唱套餐",
	private String shop_price;// "shop_price": "300.00",
	private String tuan_price;// "tuan_price": "29.00",
	private String app_price;// "app_price": "29.00",
	private String vip_price;// "vip_price": "25.00",
	private String desc;// "desc": "仅售29元，价值300元火车站店6小时欢唱套餐2选1！",
	private String like;// "like": "6",
	private String dig_url;// "dig_url": "",
	private String icon;// "icon":
						// "http://static.kenchao.com/Upload/201501/54b48ee5b5463.png",
	private String coupon_id;// "coupon_id": "8",
	private int i_like;// "i_like": 0

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getShop_price() {
		return shop_price;
	}

	public void setShop_price(String shop_price) {
		this.shop_price = shop_price;
	}

	public String getTuan_price() {
		return tuan_price;
	}

	public void setTuan_price(String tuan_price) {
		this.tuan_price = tuan_price;
	}

	public String getApp_price() {
		return app_price;
	}

	public void setApp_price(String app_price) {
		this.app_price = app_price;
	}

	public String getVip_price() {
		return vip_price;
	}

	public void setVip_price(String vip_price) {
		this.vip_price = vip_price;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getLike() {
		return like;
	}

	public void setLike(String like) {
		this.like = like;
	}

	public String getDig_url() {
		return dig_url;
	}

	public void setDig_url(String dig_url) {
		this.dig_url = dig_url;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getCoupon_id() {
		return coupon_id;
	}

	public void setCoupon_id(String coupon_id) {
		this.coupon_id = coupon_id;
	}

	public int getI_like() {
		return i_like;
	}

	public void setI_like(int i_like) {
		this.i_like = i_like;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((coupon_id == null) ? 0 : coupon_id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CouponDetail other = (CouponDetail) obj;
		if (coupon_id == null) {
			if (other.coupon_id != null)
				return false;
		} else if (!coupon_id.equals(other.coupon_id))
			return false;
		return true;
	}

	public void parse(JSONObject data) {
		setName(getString(data, "name"));
		setShop_price(getString(data, "shop_price"));
		setTuan_price(getString(data, "tuan_price"));
		setApp_price(getString(data, "app_price"));
		setVip_price(getString(data, "vip_price"));
		setDesc(getString(data, "desc"));
		setLike(getString(data, "like"));
		setDig_url(getString(data, "dig_url"));
		setIcon(getString(data, "icon"));
		setCoupon_id(getString(data, "coupon_id"));
		setI_like(getInt(data, "i_like"));
	}

	public int getInt(JSONObject obj, String id) {
		try {
			if (obj.has(id)) {
				return obj.getInt(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public String getString(JSONObject obj, String id) {
		try {
			if (obj.has(id)) {
				return obj.getString(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
}
